package org.noip.milhous;

import java.sql.Types;

public enum FIELDTYPES
{
	UserDefined("none", Types.OTHER, ""), INT("int", Types.INTEGER, 11, "Integer"), BOOL("tinyint", Types.BIT, 1, "Boolean"), DECIMAL("BigDecimal", Types.DECIMAL, "BigDecimal"), STRING("varchar",
			Types.VARCHAR, 200, "String"), LONG("int", Types.BIGINT, 20, "BigInteger"), Date("time", Types.DATE, "Date"), Blob("blob,", Types.BLOB, "Blob"), TIMESTAMP("Timestamp", Types.TIMESTAMP,
			"Timestamp"), DOUBLE("Double", Types.DOUBLE, "Double");

	private JavaSQLConversion conversions;

	private int nullType;

	private Integer defaultLen;

	private String sqlType;

	private String javaType;

	public int getNullType()
		{
			return nullType;
		}

	private FIELDTYPES(String sqlType, int NullTYPE, Integer len, String javaType)
		{
			// classList = new HashSet<String>();
			this.javaType = javaType;
			this.sqlType = sqlType;
			defaultLen = len;
			nullType = NullTYPE;
		}

	private FIELDTYPES(String sqlType, int NullTYPE, String javaType)
		{
			this(sqlType, NullTYPE, null, javaType);
		}

	public String getSQL(Integer len)
		{
			StringBuffer result = new StringBuffer(sqlType);
			if (len != null)
				{
					result.append("(" + len + ")");
				}
			else if (defaultLen != null)
				{
					result.append("(" + defaultLen + ")");
				}
			return result.toString();
		}

	public String getJava()
		{
			return javaType;
		}

	public FIELDTYPES getFieldType(String dbName, COLUMNS col)
		{
			load();
			return conversions.getDBType(dbName, col);
		}

	public FIELDTYPES getFIELDTYPE(String className)
		{
			load();
			return conversions.getJavaType(className);
		}

	public void load()
		{
			if (conversions == null)
				{
					conversions = new JavaSQLConversion();
				}
		}

}
